public class Demo10 {
    public static Object object1 = new Object();
    public static Object object2 = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            synchronized (object1){
                System.out.println("t1上object1锁");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            synchronized (object2){
                System.out.println("t1上object2锁");
            }
            System.out.println("t1线程结束");
        });
        Thread t2 = new Thread(()->{
            synchronized (object2){
                System.out.println("t2上object2锁");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            synchronized (object1){
                System.out.println("t2上object1锁");
            }
            System.out.println("t2线程结束");
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();

    }
}
